package cn.com.bluemoon.daps.api.model.factory;

import cn.com.bluemoon.daps.api.model.RemoteHandlerStdRelateService;
import cn.com.bluemoon.daps.common.constant.DapConstant;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteHandlerStdRelateServiceFallbackFactory implements FallbackFactory<RemoteHandlerStdRelateService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteHandlerStdRelateServiceFallbackFactory.class);

    @Override
    public RemoteHandlerStdRelateService create(Throwable throwable) {
        log.error("处理标准关系服务调用失败:{}", throwable.getMessage());
        return new RemoteHandlerStdRelateService() {
            @Override
            public ResultBean<Boolean> clearRelation(String standardUniqueId, DapConstant.DapStandard.StandardType standardType) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "清除标准相关信息失败");
            }
        };
    }
}
